﻿namespace Vampirewal.Core.Interface;

/// <summary>
/// VampireCore数据上下文
/// </summary>
public interface IVampirewalCoreDataContext
{
    /// <summary>
    /// 连接客户端
    /// </summary>
    SqlSugarScope Client { get; set; }
}

/// <summary>
/// VampirewalCore的SqlSugar配置
/// </summary>
public interface IVampirewalCoreSqlSugar
{
    /// <summary>
    /// 初始化数据(在CodeFirst后执行)
    /// </summary>
    void InitData();

    /// <summary>
    /// 设置客户端
    /// </summary>
    /// <param name="client"></param>
    void SetClient(ISqlSugarClient client);

    /// <summary>
    /// 配置Sqlsugar连接设置
    /// </summary>
    /// <param name="DbName"></param>
    /// <param name="ConnStr"></param>
    /// <param name="dbType"></param>
    /// <returns></returns>
    ConnectionConfig GetDbConnectionConfig(string DbName, string ConnStr, DBTypeEnum? dbType);

    /// <summary>
    /// 获取代码执行超过1秒的代码，放在OnLogExecuted
    /// </summary>
    /// <returns>超时sql所在信息</returns>
    string GetSqlExecuteTimeMoreOnceSecond();

    /// <summary>
    /// SQL执行完
    /// </summary>
    /// <param name="sql"></param>
    /// <param name="para"></param>
    void OnLogExecuted(string sql, SugarParameter[] para);

    /// <summary>
    /// SQL执行前
    /// </summary>
    /// <param name="sql"></param>
    /// <param name="para"></param>
    void OnLogExecuting(string sql, SugarParameter[] para);

    /// <summary>
    /// SQL报错
    /// </summary>
    /// <param name="exp"></param>
    void OnError(SqlSugarException exp);

    /// <summary>
    /// 数据执行过滤
    /// <para>可用于新增或修改的时候，处理CreateName或UpdateName</para>
    /// </summary>
    /// <param name="OldValue"></param>
    /// <param name="entityInfo"></param>
    void DataExecuting(object OldValue, DataFilterModel entityInfo);

    /// <summary>
    /// 查询后数据替换
    /// </summary>
    /// <param name="value"></param>
    /// <param name="entity"></param>
    void DataExecuted(object value, DataAfterModel entity);

    /// <summary>
    /// 可以修改SQL和参数的值
    /// </summary>
    /// <param name="sql">sql=newsql</param>
    /// <param name="pars">foreach(var p in pars) //修改</param>
    /// <returns></returns>
    KeyValuePair<string, SugarParameter[]> OnExecutingChangeSql(string sql, SugarParameter[] pars);

    /// <summary>
    /// 创建表(需要建表的都需要重复写)
    /// <para>使用方法：CreateTable();</para>
    /// <para>这样一个表就能成功创建了</para>
    /// </summary>
    void CodeFirst();

    /// <summary>
    /// 筛选反射获取到的表Type并筛选返回
    /// </summary>
    Type[] FilterSugarTableType(Type[] types);
}